package com.ruihang.generalibrary.ui.widget;

import android.content.Context;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.canyinghao.canrefresh.CanRefreshLayout;

/**
 * Created by Administrator on 2017/3/29.
 */

public class CustomLinearLayout extends LinearLayoutCompat implements CanRefreshLayout.IScrollView {

    private OnScrollChangedListener scrollChangedListener;

    private CanRefreshLayout.IScrollView iScrollView;

    public CustomLinearLayout(Context context) {
        super(context);
    }

    public CustomLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (scrollChangedListener != null) {
            scrollChangedListener.onScrollChangedD(this, l, t, oldl, oldt);
        }
    }

    public void setOnScrolledChangeListener(OnScrollChangedListener l) {
        this.scrollChangedListener=l;
    }

    public CustomLinearLayout setiScrollView(CanRefreshLayout.IScrollView iScrollView) {
        this.iScrollView = iScrollView;
        return this;
    }

    @Override
    public boolean canScrollUp(MotionEvent motionEvent) {
        if (iScrollView!=null){
            return iScrollView.canScrollUp(motionEvent);
        }
        return false;
    }

    @Override
    public boolean canScrollDown(MotionEvent motionEvent) {
        if (iScrollView!=null){
            return iScrollView.canScrollDown(motionEvent);
        }
        return false;
    }
}
